/**
  ******************************************************************************
  * @author     Chris
  * @since      2024/6/24 10:21
  *
  * @file       hd_mpu6050.h
  * @brief      Header file of Xxx hardware driver.
  *
  * @note       This file contains the Xxx object declaration.
  *
  * @warning    None.
  ******************************************************************************
  * Change Logs:
  *   Date          Author       Notes
  *   2024/6/24     Chris        the first version
  *
  ******************************************************************************
  */


#ifndef JLC_SKY_MPU6050_H
#define JLC_SKY_MPU6050_H

#include "pd_i2c.h"

struct MPU6050Vtbl;

/** @defgroup Object properties
  * @{
  */
typedef struct {
    I2C *i2c;

    // MPU6050 virtual table
    struct MPU6050Vtbl *vptr;
} MPU6050;
/**
 * @}
 */

/** @defgroup MPU6050 data declaration
  * @{
  */
typedef struct {
    int16_t accX;
    int16_t accY;
    int16_t accZ;

    int16_t temp;

    int16_t gyroX;
    int16_t gyroY;
    int16_t gyroZ;
} MPU6050Data;
/**
 * @}
 */

/** @defgroup Object virtual table definition
  * @{
  */
struct MPU6050Vtbl {
    void (*init)(const MPU6050 *this);

    uint8_t (*get_id)(const MPU6050 *this);

    void (*get_data)(const MPU6050 *this, MPU6050Data* data);
};
/**
 * @}
 */

/** @defgroup Object constructor and member function declaration
  * @{
  */
void MPU6050_constructor(MPU6050 *this, I2C *i2c);
/**
 * @}
 */

/** @defgroup Object virtual table function implementation
  * @{
  */
static inline void MPU6050_init(const MPU6050 *this) {
    this->vptr->init(this);
}

static inline uint8_t MPU6050_getId(const MPU6050 *this) {
    return this->vptr->get_id(this);
}

static inline void MPU6050_getData(const MPU6050 *this, MPU6050Data *data) {
    this->vptr->get_data(this, data);
}
/**
 * @}
 */


#define     MPU6050_ADDRESS         0x68

#define     MPU6050_SMPLRT_DIV      0x19
#define     MPU6050_CONFIG          0x1A
#define     MPU6050_GYRO_CONFIG     0x1B
#define     MPU6050_ACCEL_CONFIG    0x1C

#define     MPU6050_ACCEL_XOUT_H    0x3B
#define     MPU6050_ACCEL_XOUT_L    0x3C
#define     MPU6050_ACCEL_YOUT_H    0x3D
#define     MPU6050_ACCEL_YOUT_L    0x3E
#define     MPU6050_ACCEL_ZOUT_H    0x3F
#define     MPU6050_ACCEL_ZOUT_L    0x40
#define     MPU6050_TEMP_OUT_H      0x41
#define     MPU6050_TEMP_OUT_L      0x42
#define     MPU6050_GYRO_XOUT_H     0x43
#define     MPU6050_GYRO_XOUT_L     0x44
#define     MPU6050_GYRO_YOUT_H     0x45
#define     MPU6050_GYRO_YOUT_L     0x46
#define     MPU6050_GYRO_ZOUT_H     0x47
#define     MPU6050_GYRO_ZOUT_L     0x48

#define     MPU6050_PWR_MGMT_1      0x6B
#define     MPU6050_PWR_MGMT_2      0x6C
#define     MPU6050_WHO_AM_I        0x75

#endif //JLC_SKY_MPU6050_H
